﻿// ***********************************************************************
// Assembly         : NIMServerApi
// Author           : Walter
// Created          : 11-15-2016
//
// Last Modified By : Walter
// Last Modified On : 11-15-2016
// ***********************************************************************
// <copyright file="HistoryMethod.cs" company="51iface">
//     Copyright 51iface©  2016
// </copyright>
// <summary></summary>
// ***********************************************************************

using System;
using NIMServerApi.Commons;

namespace NIMServerApi.Methods
{
    public class HistoryMethod:BaseMethod
    {
        public HistoryMethod(string appKey, string appSecret):base(appKey,appSecret)
        {

        }

        /// <summary>
        /// 单聊云端历史消息查询.
        /// </summary>
        /// <param name="from">发送者accid.</param>
        /// <param name="to">接收者accid.</param>
        /// <param name="begintime">开始时间，ms.</param>
        /// <param name="endtime">截止时间，ms.</param>
        /// <param name="limit">本次查询的消息条数上限(最多100条),小于等于0，或者大于100，会提示参数错误.</param>
        /// <param name="reverse">1按时间正序排列，2按时间降序排列。其它返回参数414错误.默认是按降序排列.</param>
        /// <returns>System.String.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// Paramer 'from' is required.
        /// or
        /// Paramer 'to' is required.
        /// or
        /// Paramer 'begintime' is required.
        /// or
        /// Paramer 'endtime' is required.
        /// </exception>
        public string QuerySessionMsg(string from, string to, string begintime, string endtime, int limit,
            int reverse = 2)
        {
            if (string.IsNullOrEmpty(from))
            {
                throw new ArgumentNullException("Paramer 'from' is required.");
            }
            if (string.IsNullOrEmpty(to))
            {
                throw new ArgumentNullException("Paramer 'to' is required.");
            }
            if (string.IsNullOrEmpty(begintime))
            {
                throw new ArgumentNullException("Paramer 'begintime' is required.");
            }
            if (string.IsNullOrEmpty(endtime))
            {
                throw new ArgumentNullException("Paramer 'endtime' is required.");
            }
            string postStr = $"from={from}&to={to}&begintime={begintime}&endtime={endtime}&limit={limit}&reverse={reverse}";
            string json = NIMHttpClient.ExecutePost(appKey, appSecret, NIMCloud.NIMURI + "/history/querySessionMsg.action", postStr, "");
            return json;
        }


    }
}